﻿//===============================================================================
// Apolineo Patterns & Practices LeanEngine Framework
//===============================================================================
// Copyright © Apolineo Desenvolvimento de Sistemas Ltda.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LeanEngine.Entity;
using LeanEngine.Extensions;

namespace LeanEngine.SalesConcept.Windows.Component
{
    public class FormSelectItemBase : Form
    {
        public PlainEntity ShowDialogForSelectItem()
        {
            var form = (this as IFormSelectItemBehavior);

            if (form.IsNull())
            {
                throw new System.Exception("Form '" + this.GetType().Name + "' must implement interface 'IFormSelectItemBehavior' for use ShowDialogForSelectItem method.");
            }

            if (this.ShowDialog() == DialogResult.OK)
            {
                return form.SelectedItem;
            }

            return null;
        }
    }
}
